# Contributor: Michał Polański <michal@polanski.me>
# Maintainer: Michał Polański <michal@polanski.me>
pkgname=hcloud
_pkgname=cli
pkgver=1.17.0
pkgrel=0
pkgdesc="Command-line interface for Hetzner Cloud"
url="https://github.com/hetznercloud/cli"
options="chmod-clean"
arch="all !mips64" # limited by go
license="MIT"
makedepends="go"
subpackages="$pkgname-bash-completion"
source="$_pkgname-$pkgver.tar.gz::https://github.com/hetznercloud/cli/archive/v$pkgver.tar.gz"
builddir="$srcdir/$_pkgname-$pkgver"

export GOPATH="$srcdir"
export CGO_ENABLED=0

build() {
	go build \
		-ldflags "-w -X github.com/hetznercloud/cli/cli.Version=v$pkgver" \
		-v \
		./cmd/hcloud
	./hcloud completion bash > "$builddir"/$pkgname.bash
}

check() {
	go test ./...
}

package() {
	install -Dm755 "$builddir"/hcloud "$pkgdir"/usr/bin/$pkgname
	install -Dm644 "$builddir"/$pkgname.bash \
		"$pkgdir"/usr/share/bash-completion/completions/$pkgname
}

cleanup_srcdir() {
	go clean -modcache
	default_cleanup_srcdir
}

sha512sums="cfc9dafe6148674e2001edc4e3066cc6bd6b9b46b276f8fc687e2f5d97c5b758ba24c334b376d7d6591a3b33b3db461cab59b0f10bcf0df73cb4db8c30a55856  cli-1.17.0.tar.gz"
